package com.xyht.sca_s.student_manage_system.modules.dormitory.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryFloorAddReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryFloorDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryFloorUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.service.SmsDormitoryFloorService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 宿舍楼层管理表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-08
 */
@RestController
@RequestMapping("/dormitory/floor")
@SecretBody
public class SmsDormitoryFloorController {

    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private SmsDormitoryFloorService smsDormitoryFloorService;

    @ApiOperation("添加楼层")
    @PostMapping("/add")
    public ResponseResult addDormitoryFloor(HttpServletRequest request, @RequestBody SmsDormitoryFloorAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryFloorService.addDormitoryFloor(userId,addReq);
    }

    @ApiOperation("删除楼层")
    @PostMapping("/deleted")
    public ResponseResult deletedDormitoryFloor(@RequestBody SmsDormitoryFloorDeletedReq deletedReq){
        return smsDormitoryFloorService.deletedDormitoryFloor(deletedReq);
    }

    @ApiOperation("修改楼层")
    @PostMapping("/update")
    public ResponseResult updateDormitoryFloor(@RequestBody SmsDormitoryFloorUpdateReq updateReq){
        return smsDormitoryFloorService.updateDormitoryFloor(updateReq);
    }

    @ApiOperation("查询楼层列表")
    @GetMapping("/getDormitoryFloorList")
    public ResponseResult getDormitoryFloorList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "buildingId", required = false) String buildingId,
                                                @RequestParam(value = "name", required = false) String name){
        return smsDormitoryFloorService.getDormitoryFloorList(pageNum,pageSize,name,buildingId);
    }


}

